<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主子表提交')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
<div class="main-content">
    <form class="form-horizontal m" id="form-dw-edit" th:object="${etlDrawDw}">
        <h4 class="form-header h4">数据仓库信息</h4>
        <input name="idDrawDw" th:field="*{idDrawDw}" type="hidden">
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">名称：</label>
                    <div class="col-sm-8">
                        <input name="na" th:field="*{na}" class="form-control" type="text" disabled>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">所属系统：</label>
                    <div class="col-sm-8">
                        <select name="sdSys" class="form-control m-b" th:with="type=${@baseSd.getItem('hos_sys')}" disabled>
                            <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">DW表：</label>
                    <div class="col-sm-8">
                        <input name="cdTb" th:field="*{cdTb}" class="form-control" type="text" disabled>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">ods目标表：</label>
                    <div class="col-sm-8">
                        <input name="cdTbTarOds" th:field="*{cdTbTarOds}" class="form-control" type="text" disabled>
                    </div>
                </div>
            </div>
        </div>
        <h4 class="form-header h4">字段对照</h4>
        <div class="row">
            <div class="col-sm-12">
                <div class="col-sm-12 select-table table-striped">
                    <table class="table table-bordered">
                        <colgroup>
                            <col width="20%">
                            <col width="15%">
                            <col width="25%">
                            <col width="25%">
                            <col width="15%">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>ODS列名</th>
                            <th>状态</th>
                            <th>DW字段(维度、度量、日期)</th>
                            <th>DW字段(时分秒)</th>
                            <th>索引标志</th>
                        </tr>
                        </thead>
                        <tbody id="fildLIst" >
                        <tr th:each="item:${fldVOList}">
                        <td th:text="${item.odsFid}"></td>
                        <td>
                            <select class='form-control' disabled>
                                <option value="0" th:selected="${item.odsFidType==0}">新建</option>
                                <option value="1" th:selected="${item.odsFidType==1}">不变</option>
                                <option value="2" th:selected="${item.odsFidType==2}">已删</option>
                            </select>
                        </td>
                        <td>
                            <select name="dwFid1" class="form-control m-b" th:disabled="${item.odsFidType==2}">
                                <option value=""></option>
                                <option th:each="pubfld:${pubflds}" th:text="${pubfld.na}" th:value="${pubfld.idPubfld}" th:selected="${item.dwFid1==pubfld.idPubfld}"></option>
                            </select>
                        </td>
                        <td>
                            <select name="dwFid2" class="form-control m-b" th:disabled="${item.odsFidType==2}">
                                <option value=""></option>
                                <option th:each="timefld:${timeflds}" th:text="${timefld.na}" th:value="${timefld.idPubfld}" th:selected="${item.dwFid2==timefld.idPubfld}"></option>
                            </select>
                        </td>
                        <td>
                            <select class='form-control' th:disabled="*{euStatus != 0} or ${item.odsFidType==2}" >
                                <option value="0" th:selected="${item.fgIndex==0}">否</option>
                                <option value="1" th:selected="${item.fgIndex==1}">是</option>
                            </select>
                        </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: bootstrap-select-js" />
<script th:src="@{/js/jquery.tmpl.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "etl/dw";
    /* 主子表-提交 */
    function submitHandler(index, layero){

        var data=[],dataItem;
        var idDrawDw=$("#form-dw-edit").find("input[name='idDrawDw']").val();
        var cdTbDw=$("#form-dw-edit").find("input[name='cdTb']").val();
        var fldDwMain,fldDwSlave,fldOds,fgIndex;
        $.each($("#fildLIst tr"),function (index,item) {
            var tds = $(this).find("td");
            fldDwMain =$(tds[2]).find("select").val();
            fldDwSlave =$(tds[3]).find("select").val();
            fgIndex = $(tds[4]).find("select").val();
            fldOds = $(tds[0]).html();
            if(fldDwMain!="") {
                dataItem = {"idDrawDw":idDrawDw,"cdTbDw":cdTbDw,"fldDwMain":fldDwMain,"fldDwSlave":fldDwSlave,"fldOds":fldOds,"fgIndex":fgIndex};
                data.push(dataItem);
            }
        });
        if(data.length>0) {
            $.ajax({
                url: prefix+"/saveFld",
                cache: false,
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(data),
                contentType: 'application/json;charset=UTF-8',
                success: function (result) {
                    if(result.code=="0") {
                        $.modal.close();
                    }
                }
            });
        }
    }
</script>
</body>
</html>
